using System;
using System.Text.RegularExpressions;
namespace BMC.ARSystem
{
	internal class ARXCharReader : ARXDataTypeReader
	{
		internal ARXCharReader()
		{
		}
		public static string UnescapeString(string val)
		{
			Regex regex = new Regex("\\\\.|[^\\\\]");
			return regex.Replace(val, new MatchEvaluator(ARXCharReader.UnescapeMatch));
		}
		public static string EscapeString(string val)
		{
			Regex regex = new Regex("\\\\|\\00D|\\\00A");
			return regex.Replace(val, new MatchEvaluator(ARXCharReader.EscapeMatch));
		}
		private static string UnescapeMatch(Match match)
		{
			if (match.get_Value() == "\\\"")
			{
				return "\"";
			}
			if (match.get_Value() == "\\n")
			{
				return "\n";
			}
			if (match.get_Value() == "\\r")
			{
				return "";
			}
			if (match.get_Value() == "\\\\")
			{
				return "\\";
			}
			return match.get_Value();
		}
		private static string EscapeMatch(Match match)
		{
			if (match.get_Value() == "\\")
			{
				return "\\\\";
			}
			if (match.get_Value() == "\n")
			{
				return "\\n";
			}
			if (match.get_Value() == "\r")
			{
				return "\\r";
			}
			return match.get_Value();
		}
		internal override object ReadValue(string val)
		{
			return ARXCharReader.UnescapeString(val);
		}
	}
}
